function g2 = dynamic_g2(T, y, x, params, steady_state, it_, T_flag)
% function g2 = dynamic_g2(T, y, x, params, steady_state, it_, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T             [#temp variables by 1]     double   vector of temporary terms to be filled by function
%   y             [#dynamic variables by 1]  double   vector of endogenous variables in the order stored
%                                                     in M_.lead_lag_incidence; see the Manual
%   x             [nperiods by M_.exo_nbr]   double   matrix of exogenous variables (in declaration order)
%                                                     for all simulation periods
%   steady_state  [M_.endo_nbr by 1]         double   vector of steady state values
%   params        [M_.param_nbr by 1]        double   vector of parameter values in declaration order
%   it_           scalar                     double   time period for exogenous variables for which
%                                                     to evaluate the model
%   T_flag        boolean                    boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   g2
%

if T_flag
    T = rbc_chapter4.dynamic_g2_tt(T, y, x, params, steady_state, it_);
end
g2_i = zeros(17,1);
g2_j = zeros(17,1);
g2_v = zeros(17,1);

g2_i(1)=1;
g2_i(2)=1;
g2_i(3)=1;
g2_i(4)=1;
g2_i(5)=1;
g2_i(6)=1;
g2_i(7)=2;
g2_i(8)=2;
g2_i(9)=2;
g2_i(10)=2;
g2_i(11)=2;
g2_i(12)=2;
g2_i(13)=2;
g2_i(14)=3;
g2_i(15)=3;
g2_i(16)=3;
g2_i(17)=3;
g2_j(1)=8;
g2_j(2)=12;
g2_j(3)=13;
g2_j(4)=14;
g2_j(5)=18;
g2_j(6)=19;
g2_j(7)=7;
g2_j(8)=10;
g2_j(9)=22;
g2_j(10)=13;
g2_j(11)=14;
g2_j(12)=18;
g2_j(13)=19;
g2_j(14)=13;
g2_j(15)=11;
g2_j(16)=3;
g2_j(17)=1;
g2_v(1)=params(1)/((1-y(3))*(1-y(3)));
g2_v(2)=g2_v(1);
g2_v(3)=(-(params(1)*y(2)*((-(1-y(3)))-(1-y(3)))))/((1-y(3))*(1-y(3))*(1-y(3))*(1-y(3)))-T(1)*getPowerDeriv(y(3),(-params(3)),2);
g2_v(4)=(-(T(6)*T(9)));
g2_v(5)=g2_v(4);
g2_v(6)=(-(T(2)*(1-params(3))*getPowerDeriv(y(4),params(3),2)));
g2_v(7)=(-((-y(5))*(y(2)+y(2))))/(y(2)*y(2)*y(2)*y(2));
g2_v(8)=(-1)/(y(2)*y(2));
g2_v(9)=g2_v(8);
g2_v(10)=(-(params(2)*T(3)*T(11)));
g2_v(11)=(-(params(2)*T(7)*T(10)));
g2_v(12)=g2_v(11);
g2_v(13)=(-(params(2)*T(4)*params(3)*getPowerDeriv(y(4),params(3)-1,2)));
g2_v(14)=(-(T(5)*T(11)));
g2_v(15)=(-(T(7)*T(8)));
g2_v(16)=g2_v(15);
g2_v(17)=(-(T(4)*getPowerDeriv(y(1),params(3),2)));
g2 = sparse(g2_i,g2_j,g2_v,3,25);
end
